<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Rules as M;
use app\admin\model\Menus;
//角色
class Rules extends Controller
{
    public function index()
    { 
        return $this->fetch();
    }
    
    /*
     * 获取josn详情
     */
    public function get_josn()
    { 
        $m = new M();
        $menus = new Menus();
        $rs = $m->getAll();
        $lists = ['code' => 0, 'msg' => '', 'data' =>[]];
        foreach ($rs as $k=>$v)
        {
            $v['menulist'] = $menus->getNameList($v['menus']);
            $lists['data'][] = $v;
        }
        return $lists;
    }
    
    /*
     * 添加页面
     */
    public function add()
    { 
        $m = new Menus();
        $menus = $m->getAllMenustree();//获得所有菜单列表
        $this->assign('menus', $menus);
        return $this->fetch();
    }
    
    /*
     * 添加提交
     */
    public function add_submit()
    { 
        $m = new M();
        return $m->add();
    }    
    
    /*
     * 修改页面
     */
    public function edit()
    { 
        $m = new Menus();
        $menus = $m->getAllMenustree();
        $this->assign('menus', $menus);
        
        $rule = new M();
        $s = $rule->getById(input('id'));
        $this->assign('id', input('id'));
        $this->assign('s', $s);
        $this->assign('menus_arr', empty($s->menus)?[]: explode(',', $s->menus));
        return $this->fetch();
    }   
    
    /*
     * 修改提交
     */
    public function edit_submit()
    { 
        $m = new M();
        return $m->edit();
    } 
    
    /*
     * 删除
     */
    public function del_submit()
    { 
        $m = new M();
        return $m->del();
    }  
}
